#include <fs.h>
#include <status.h>

int default_file_close(file_t* file) {
    return 0;
}

int default_file_sync(file_t* file) {
    return 0;
}

int default_file_seek(inode_t* inode, size_t offset) {
    return 0;
}

int default_inode_open(inode_t* this, file_t* file) {
    return 0;
}

int default_file_read(inode_t* inode, void* buffer, size_t len, size_t fpos) {
    return ENOSET;
}

int default_file_write(inode_t* inode, void* buffer, size_t len, size_t fpos) {
    return ENOSET;
}

int default_inode_lookup(inode_t* this, dentry_t* dentry) {
    return ENOENT;
}

int default_inode_rename(inode_t* from_inode,
    dentry_t* from_dentry,
    dentry_t* to_dentry) {
    return 0;
}

int default_inode_sync(inode_t* this) {
    return 0;
}

int default_inode_rmdir(inode_t* this, dentry_t* dir) {
    return ENOSET;
}

int default_inode_mkdir(inode_t* this, dentry_t* dir) {
    return ENOSET;
}

int default_file_readdir(file_t* file, dirent_t* dirent) {
    unsigned i = 2;
    dentry_t* pos, * n;
    list_for_each(pos, n, &file->dentry->children, siblings) {
        if (i < dirent->d_offset) {
            i++;
            continue;
        }
        dirent_assign(dirent, pos->name.val, pos->name.len, 0);
        return 1;
    }
    return 0;
}

f_ops default_file_ops = {
    .close = default_file_close,
    .read = default_file_read,
    .seek = default_file_seek,
    .sync = default_file_sync,
    .readdir = default_file_readdir
};

inode_ops default_inode_ops = {
    .lookup = default_inode_lookup,
    .open = default_inode_open,
    .mkdir = default_inode_mkdir,
    .rmdir = default_inode_rmdir,
    .sync = default_inode_sync
};